<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <script src="./layui/layui.js"></script>
    <style>
        body {
            background: linear-gradient(to right, #c0c0aa, #1cefff);
        }

        .layui-input {
            width: 230px;
        }
    </style>
</head>

<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                    class="layui-input phoneNumber">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码框</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                    autocomplete="off" class="layui-input pwsNumber">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开关</label>
            <div class="layui-input-block">
                <input type="checkbox" name="switch" lay-skin="switch" class="check">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button">立即提交</button>
            </div>
        </div>
    </form>
</body>
<script src="../js_common/AllFunction.js"></script>
<script>
    document.querySelector('.layui-btn').onclick=function(){
        let phoneNumber=document.querySelector('.phoneNumber').value;
        let pswNumber=document.querySelector('.pwsNumber').value;
        let xhr=new XMLHttpRequest;
        xhr.open('POST','http://phpclub.org.cn/edu/server/regist.php');
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(`mobile=${phoneNumber}&password=${pswNumber}`);
        xhr.onload=function(){
            let response = JSON.parse(xhr.responseText);
                // 服务端返回的是JSON格式必定存在code msg data信息
                if(response.code != 100){
                    // layer.msg属于layui框架内置所封装的功能
                    layer.msg(response.msg,{icon: 5}); 
                }else{
                    location.href = './login.html';
                }
            }
    }
</script>

</html>